import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'big-user',
  () => {
    //user  数据
    const user = ref({})
    const setUser = (data) => {
      user.value = data
    }
    const clearUser = () => {
      user.value = {}
    }

    // token  数据
    const token = ref('')
    const setToken = (data) => {
      token.value = data
    }
    const clearToken = () => {
      token.value = ''
    }
    const logout = () => {
      clearUser()
      clearToken()
    }

    return { user, setUser, clearUser, token, setToken, clearToken, logout }
  },
  {
    persist: true //开启持久化
  }
)
